package com.example.common.utils.result;

/**
 * <p>
 *
 * </p>
 *
 * @author 12071
 * @date 2022/8/3 14:27
 */
public class R<T> {

    private static final int OK = 0;
    private static final int FAIL = 1;
    /**
     * 服务端数据
     */
    private T data;
    /**
     * 状态码
     */
    private int status;
    /**
     * 描述信息
     */
    private String error = "";

    public static R isOk() {
        return new R().status(OK);
    }

    public static R isFail() {
        return new R().status(FAIL);
    }

    public static R isFail(Throwable e) {
        return isFail().error(e);
    }


    public R error(Throwable e) {
        this.setError(e.getMessage());
        return this;
    }

    public R error(String errorMessage) {
        this.setError(errorMessage);
        return this;
    }

    public R<T> data(T data) {
        this.setData(data);
        return this;
    }

    public R status(int status) {
        this.setStatus(status);
        return this;
    }

    public R() {

    }


    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }
}
